home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Amiga Classic Collection
/
The Amiga Classic Collection - Disc 1.iso
/
Education
/
ED16-CrosswordCreator.DMS
/
ED16-CrosswordCreator.adf
/
Source
/
PreProcessor.mod
< prev
next >
Wrap
Text File
|
1991-07-13
|
6KB
|
226 lines
(***************************************************************************
:Program. PreProcessor
:Author. Jürgen Weinelt
:Address. Zur Kanzel 1, D-8783 Hammelburg, Germany
:Version. V2.0
:Copyright. Freeware; copy it, but make no profit!
:Language. Modula-II
:Translator. M2Amiga V4.096d
:Imports. FileReq
:Contents. PreProcessor is part of the "Cross" (crossword puzzle
:Contents. Creator) package.
:Contents. PreProcessor takes any amiga ascii text file as input
:Contents. and produces a CPC word data file as output.
:History. V1.0 08-jan-91 first major release on AMOK
:History. V1.1 06-feb-91 minor changes
:History. V1.2 28-jun-91 changed to m2amiga v4.096d
:History. V2.0 17-aug-91 code cleanup for big release
**************************************************************************)
MODULE PreProcessor;
IMPORT Arts;
IMPORT DosL;
IMPORT FileReq;
IMPORT FileSystem;
IMPORT Heap;
IMPORT InOut;
IMPORT String;
IMPORT SYSTEM;
CONST
wordlen=25;
TYPE
WordString=ARRAY[0..wordlen] OF CHAR;
WordNodePtr=POINTER TO WordNode;
WordNode=
RECORD
word: WordString;
left,right: WordNodePtr;
END;
VAR
inf,outf: FileSystem.File;
inname,outname: FileReq.FileString;
wrd: WordString;
frd: FileReq.FileRequestData;
root: WordNodePtr;
act: LONGINT;
PROCEDURE GetChar(VAR file: FileSystem.File; VAR c,c2: CHAR): BOOLEAN;
VAR
legal: BOOLEAN;
BEGIN
FileSystem.ReadChar(file,c);
CASE c OF
|"a".."z":
c:=CHAR(INTEGER(c)-INTEGER("a")+INTEGER("A")); (* capitalize *)
c2:="\o";
legal:=TRUE;
|"A".."Z":
legal:=TRUE;
c2:="\o";
|"ä","Ä":
c:="A"; c2:="E"; legal:=TRUE;
|"ö","Ö":
c:="O"; c2:="E"; legal:=TRUE;
|"ü","Ü":
c:="U"; c2:="E"; legal:=TRUE;
|"ß": c:="S"; c2:="S"; legal:=TRUE;
|ELSE legal:=FALSE;
END;
RETURN legal;
END GetChar;
PROCEDURE GetWord(VAR file: FileSystem.File; VAR wrd: WordString);
VAR
c,c2: CHAR;
inx: INTEGER;
legal: BOOLEAN;
BEGIN
wrd[0]:="\o";
REPEAT
legal:=GetChar(file,c,c2);
UNTIL (legal) OR (file.eof);
IF (NOT file.eof) THEN
wrd[0]:=c;
IF c2#"\o" THEN
wrd[1]:=c2;
inx:=2;
ELSE
inx:=1;
END;
REPEAT
legal:=GetChar(file,c,c2);
IF legal THEN
wrd[inx]:=c;
INC(inx);
IF c2#"\o" THEN
wrd[inx]:=c2;
INC(inx);
END;
END;
UNTIL (inx>=wordlen) OR (NOT legal) OR (file.eof);
IF inx>wordlen THEN
DEC(inx);
END;
wrd[inx]:="\o";
END;
END GetWord;
PROCEDURE Remember(VAR w: WordString; VAR n: WordNodePtr);
BEGIN
(* builds a binary tree to store the words in *)
IF n=NIL THEN
Heap.Allocate(n,SIZE(WordNode));
Arts.Assert(n#NIL,SYSTEM.ADR("ERROR: OUT OF MEMORY"));
n^.word:=w;
ELSE
IF String.Length(w)<String.Length(n^.word) THEN
Remember(w,n^.right);
END;
IF String.Length(w)>String.Length(n^.word) THEN
Remember(w,n^.left);
END;
IF String.Length(w)=String.Length(n^.word) THEN
CASE String.Compare(n^.word,w) OF
|1..wordlen+1:
Remember(w,n^.left);
|-wordlen-1..-1:
Remember(w,n^.right);
|ELSE (* NOP *)
END;
END;
END;
END Remember;
PROCEDURE PutWord(n: WordNodePtr; VAR f: FileSystem.File);
VAR
act: LONGINT;
(* traverses the binary tree and outputs the words alphabetically *)
BEGIN
IF (n^.left#NIL) THEN
PutWord(n^.left,f);
END;
FileSystem.WriteBytes(f,SYSTEM.ADR(n^.word),String.Length(n^.word),act);
FileSystem.WriteChar(f,"\n");
IF (n^.right#NIL) THEN
PutWord(n^.right,f);
END;
END PutWord;
BEGIN
InOut.WriteString("\n\nCrossword Puzzle Creator: Word file PreProcessor\n");
InOut.WriteString("------------------------------------------------\n");
InOut.WriteString("Copyright © 1991 by J. Weinelt\n\n");
InOut.WriteString("This is FreeWare; non-commercial distribution is encouraged\n");
InOut.WriteString("No liabilities or warranties assumed; use at your own risk!\n\n");
InOut.WriteString("Purpose:\n");
InOut.WriteString(" Takes any ascii text file as input\n");
InOut.WriteString(" Writes an CPC word data file as output\n\n");
InOut.WriteString("PreProcessor has no command line parameters; file selection\n");
InOut.WriteString("is completely done with file requesters.\n\n");
DosL.Delay(100);
root:=NIL;
FileReq.MakeFRD("Open input file","","",NIL,100,20,frd);
FileReq.FileReq(frd,inname);
IF String.Length(inname)>0 THEN
FileSystem.Lookup(inf,inname,5000,FALSE);
Arts.Assert(inf.res=FileSystem.done,SYSTEM.ADR("ERROR: CAN'T OPEN INPUT FILE"));
InOut.WriteString("Reading ");
InOut.WriteString(inname);
InOut.WriteString("... please wait!\n\n");
REPEAT
GetWord(inf,wrd);
IF NOT (
(String.Length(wrd)<2) OR
(String.Length(wrd)>wordlen) OR
(NOT ODD(String.Length(wrd)))
)
OR (String.Length(wrd)=2)
THEN
Remember(wrd,root);
END;
UNTIL inf.eof;
frd.h:="Open output file";
FileReq.FileReq(frd,outname);
IF String.Length(outname)>0 THEN
FileSystem.Lookup(outf,outname,5000,TRUE);
Arts.Assert(outf.res=FileSystem.done,SYSTEM.ADR("ERROR: CAN'T OPEN OUTPUT FILE"));
InOut.WriteString("Writing ");
InOut.WriteString(outname);
InOut.WriteString("... please wait!\n\n");
PutWord(root,outf);
FileSystem.WriteBytes(outf,SYSTEM.ADR("***END***"),9,act);
FileSystem.WriteChar(outf,"\n");
InOut.WriteString("Finished. Please edit output file with an ASCII editor and remove\n");
InOut.WriteString("all unwanted words.\n\n");
InOut.WriteString("Goodbye.\n\n");
END;
END;
FileSystem.Close(inf);
FileSystem.Close(outf);
END PreProcessor.